import * as server from "@minecraft/server";
import * as effect_machine from "./effect_machine";
import * as machine_gate from "./machine_gate";
import * as realm_property from "../system/realm_property";
import * as derived_tools from "../system/derived_tools";
import * as native_tools from "../system/native_tools";
import * as achieve_plan from "../system/achieve_plan";
import * as math_tools from "../system/math_tools";
const defaultTag = 'data_tag:magic_tool.series';
;
function InteractComponentTrigger(source) {
    const block = source.block;
    const state = source.block.permutation;
    const dimension = source.dimension;
    const player = source.player;
    const container = player?.getComponent('minecraft:inventory')?.container;
    const item = container?.getItem(player?.selectedSlotIndex ?? 0);
    return { block, state, dimension, player, container, item };
}
;
export function CountingModuleTrigger() {
    return {
        onPlayerInteract(source) {
            const analysis = InteractComponentTrigger(source);
            if (!analysis.item?.hasTag(defaultTag))
                return;
            const input = analysis.state.getState('STATE:input');
            native_tools.TrySetPermutation(analysis.block, 'STATE:input', input != 10 ? input + 1 : 1);
            native_tools.TrySetPermutation(analysis.block, 'STATE:count', 1);
            analysis.player?.playSound('tile.piston.out');
            derived_tools.FloatingTextDisplay(analysis.block, '<§l§e 计数模块 §r> : §l§9' + (input != 10 ? input + 1 : 1));
        }
    };
}
;
export function controlPanelTrigger() {
    return {
        onPlayerInteract(source) {
            const analysis = InteractComponentTrigger(source);
            if (analysis.item?.hasTag(defaultTag)) {
                const note = analysis.state.getState('STATE:rune_note');
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_note', note != 7 ? note + 1 : 0);
                analysis.player?.playSound('tile.piston.out');
                switch (note) {
                    case 0:
                        analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§9 海蓝模式 §r]');
                        break;
                    case 1:
                        analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§4 赤焰模式 §r]');
                        break;
                    case 2:
                        analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§2 森绿模式 §r]');
                        break;
                    case 3:
                        analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§6 橙岩模式 §r]');
                        break;
                    case 4:
                        analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§5 紫雷模式 §r]');
                        break;
                    case 5:
                        analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§l 白星模式 §r]');
                        break;
                    case 6:
                        analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§l§0 黑渊模式 §r]');
                        break;
                    case 7:
                        analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§l 虚无模式 §r]');
                        break;
                    default: break;
                }
            }
            else {
                const note = analysis.state.getState('STATE:rune_note');
                if (analysis.state.getState('STATE:stage') != 0)
                    return;
                if (note != 0) {
                    native_tools.TrySetPermutation(analysis.block, 'STATE:stage', 1);
                    analysis.player?.playSound('conduit.activate');
                    analysis.player?.sendMessage('| §l交互终端§r | : §6信号已发送');
                }
                else {
                    analysis.player?.playSound('random.click');
                    analysis.player?.sendMessage('| §l交互终端§r | : §4当前操作无法执行!§r\n| §l交互终端§r | : 使用§l§6 魔晶起子 §r调整| 信号类型 |');
                }
            }
        }
    };
}
;
export function LogicInverterTrigger() {
    return {
        onPlayerInteract(source) {
            const analysis = InteractComponentTrigger(source);
            if (!analysis.item?.hasTag(defaultTag))
                return;
            const price = analysis.state.getState('STATE:price');
            native_tools.TrySetPermutation(analysis.block, 'STATE:price', price != 9 ? price + 1 : 1);
            analysis.player?.playSound('tile.piston.out');
            analysis.player?.sendMessage('| 参数设置 | : §l§e逻辑元件§r[§6 运行周期§r] -> §u' + (price != 9 ? price + 1 : 1));
        }
    };
}
;
export function signalFilteringTrigger() {
    return {
        onPlayerInteract(source) {
            const analysis = InteractComponentTrigger(source);
            if (!analysis.item?.hasTag(defaultTag))
                return;
            const note = analysis.state.getState('STATE:rune_note');
            native_tools.TrySetPermutation(analysis.block, 'STATE:rune_note', note != 7 ? note + 1 : 0);
            analysis.player?.playSound('tile.piston.out');
            switch (note) {
                case 0:
                    analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§9 海蓝模式 §r]');
                    break;
                case 1:
                    analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§4 赤焰模式 §r]');
                    break;
                case 2:
                    analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§2 森绿模式 §r]');
                    break;
                case 3:
                    analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§6 橙岩模式 §r]');
                    break;
                case 4:
                    analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§5 紫雷模式 §r]');
                    break;
                case 5:
                    analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§l 白星模式 §r]');
                    break;
                case 6:
                    analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§l§0 黑渊模式 §r]');
                    break;
                case 7:
                    analysis.player?.sendMessage('| 参数设置 | : §l§e交互终端§r[§l 虚无模式 §r]');
                    break;
                default: break;
            }
        }
    };
}
;
export function PackageDeliveryTrigger() {
    return {
        onPlayerInteract(source) {
            const analysis = InteractComponentTrigger(source);
            if (!analysis.item?.hasTag(defaultTag))
                return;
            const face = analysis.state.getState('minecraft:block_face');
            analysis.player?.playSound('tile.piston.in');
            switch (face) {
                case 'down':
                    native_tools.TrySetPermutation(analysis.block, 'minecraft:block_face', 'up');
                    break;
                case 'up':
                    native_tools.TrySetPermutation(analysis.block, 'minecraft:block_face', 'north');
                    break;
                case 'north':
                    native_tools.TrySetPermutation(analysis.block, 'minecraft:block_face', 'south');
                    break;
                case 'south':
                    native_tools.TrySetPermutation(analysis.block, 'minecraft:block_face', 'west');
                    break;
                case 'west':
                    native_tools.TrySetPermutation(analysis.block, 'minecraft:block_face', 'east');
                    break;
                case 'east':
                    native_tools.TrySetPermutation(analysis.block, 'minecraft:block_face', 'down');
                    break;
                default: break;
            }
        }
    };
}
;
export function CollectionTrigger() {
    return {
        onPlayerInteract(source) {
            const analysis = InteractComponentTrigger(source);
            if (!analysis.item?.hasTag(defaultTag))
                return;
            const value = analysis.state.getState('STATE:value');
            native_tools.TrySetPermutation(analysis.block, 'STATE:value', value != 4 ? value + 1 : 0);
            analysis.player?.playSound('tile.piston.out');
            analysis.player?.playSound('random.click');
            switch (value) {
                case 1:
                    analysis.player?.sendMessage('| 参数设置 | : §l§e物资收集§r[§4 工作半径: 16 §r]');
                    break;
                case 2:
                    analysis.player?.sendMessage('| 参数设置 | : §l§e物资收集§r[§4 工作半径: 24 §r]');
                    break;
                case 3:
                    analysis.player?.sendMessage('| 参数设置 | : §l§e物资收集§r[§4 工作半径: 32 §r]');
                    break;
                case 4:
                    analysis.player?.sendMessage('| 参数设置 | : §l§e物资收集§r[§4 工作半径: 8 §r]');
                    break;
                default: break;
            }
        }
    };
}
;
export function ParameterTrigger() {
    return {
        onPlayerInteract(source) {
            const analysis = InteractComponentTrigger(source);
            if (!analysis.item?.hasTag(defaultTag))
                return;
            const value = analysis.state.getState('STATE:value');
            native_tools.TrySetPermutation(analysis.block, 'STATE:value', value != 5 ? value + 1 : 0);
            analysis.player?.playSound('tile.piston.out');
            analysis.player?.sendMessage({
                rawtext: [
                    native_tools.BlockTranslate(analysis.block),
                    { text: `: 已修改至[§6 预设参数 §r]数值 -> ${value != 5 ? value + 1 : 0}` }
                ]
            });
        }
    };
}
;
export function SusceptorTrigger() {
    return {
        onPlayerInteract(source) {
            const analysis = InteractComponentTrigger(source);
            if (!analysis.item?.hasTag(defaultTag))
                return;
            const value = analysis.state.getState('STATE:value');
            native_tools.TrySetPermutation(analysis.block, 'STATE:value', value != 5 ? value + 1 : 0);
            analysis.player?.playSound('tile.piston.out');
            analysis.player?.sendMessage({
                rawtext: [
                    native_tools.BlockTranslate(analysis.block),
                    { text: `: 已修改至[§6 最大负载 §r]参数 -> ${value != 5 ? value + 1 : 0}` }
                ]
            });
        }
    };
}
;
export function PlaneGateTrigger() {
    return {
        onPlayerInteract(source) {
            const analysis = InteractComponentTrigger(source);
            if (analysis.item?.typeId == analysis.block.typeId)
                return;
            if (analysis.state.getState('STATE:rune_type') == 0) {
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 7);
                analysis.player?.playSound('open.bamboo_wood_door');
            }
            else if (analysis.state.getState('STATE:rune_type') != 0) {
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
                analysis.player?.playSound('open.bamboo_wood_door');
                machine_gate.Urgent(analysis.block);
            }
        }
    };
}
;
export function VerticalGateTrigger() {
    return {
        onPlayerInteract(source) {
            const analysis = InteractComponentTrigger(source);
            if (analysis.item?.typeId == analysis.block.typeId) {
                analysis.player?.playSound('place.amethyst_block');
                machine_gate.AboveStacking(analysis.block);
                return;
            }
            ;
            if (analysis.state.getState('STATE:rune_type') == 0 && analysis.state.getState('STATE:about') != 0) {
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 7);
                analysis.player?.playSound('open.bamboo_wood_door');
            }
            else if (analysis.state.getState('STATE:rune_type') != 0 && analysis.state.getState('STATE:about') != 0) {
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
                analysis.player?.playSound('open.bamboo_wood_door');
                machine_gate.Urgent(analysis.block);
            }
        }
    };
}
;
export function PortalAboveTrigger() {
    return {
        onPlayerInteract(source) {
            const analysis = InteractComponentTrigger(source);
            if (analysis.item?.typeId == analysis.block.typeId)
                return;
            native_tools.TrySpawnParticle(analysis.block.dimension, 'constant:prompt_transport_above', analysis.block.bottomCenter());
            native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 9);
            analysis.player?.playSound('conduit.activate');
            machine_gate.AboveTeleport(analysis.block);
        }
    };
}
;
export function PortalBelowTrigger() {
    return {
        onPlayerInteract(source) {
            const analysis = InteractComponentTrigger(source);
            if (analysis.item?.typeId == analysis.block.typeId)
                return;
            native_tools.TrySpawnParticle(analysis.block.dimension, 'constant:prompt_transport_below', analysis.block.center());
            native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 9);
            analysis.player?.playSound('conduit.activate');
            machine_gate.BelowTeleport(analysis.block);
        }
    };
}
;
export function SpecialAlloyPotTrigger() {
    return {
        onPlayerInteract(source) {
            const analysis = InteractComponentTrigger(source);
            if (analysis.item?.typeId == analysis.block.typeId)
                return;
            if (!analysis.player || !analysis.container)
                return;
            const item = analysis.container.getItem(analysis.player.selectedSlotIndex);
            if (!item)
                return;
            if (analysis.state.getState('STATE:flame') == 1 && analysis.state.getState('STATE:water') == 1 && analysis.state.getState('STATE:count') == 9) {
                const anchor = math_tools.Vector.toString(analysis.block.above()?.bottomCenter(), { delimiter: ' ' });
                analysis.dimension.runCommand(`loot spawn ${anchor} loot random_soup`);
                native_tools.TrySetPermutation(analysis.block, 'STATE:flame', 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:water', 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:count', 0);
                analysis.player?.playSound('bucket.empty_wate');
            }
            else if (analysis.state.getState('STATE:flame') == 1 && analysis.state.getState('STATE:water') == 1 && analysis.state.getState('STATE:count') != 9) {
                native_tools.TrySetPermutation(analysis.block, 'STATE:count', analysis.state.getState('STATE:count') + 1);
                analysis.player?.playSound('random.swim');
            }
            else
                switch (item?.typeId) {
                    case 'minecraft:water_bucket':
                        analysis.dimension.spawnItem(new server.ItemStack('minecraft:bucket'), analysis.block.center());
                        analysis.player?.playSound('bucket.empty_water');
                        native_tools.TrySetPermutation(analysis.block, 'STATE:water', 1);
                        analysis.container.setItem(analysis.player.selectedSlotIndex);
                        break;
                    case 'minecraft:flint_and_steel':
                        native_tools.TrySetPermutation(analysis.block, 'STATE:flame', 1);
                        analysis.player?.playSound('fire.ignite');
                        break;
                }
        }
    };
}
;
export function MetalCamouflageTrigger() {
    return {
        onPlayerInteract(source) {
            const analysis = InteractComponentTrigger(source);
            if (analysis.item?.typeId == analysis.block.typeId)
                return;
            if (!analysis.player || !analysis.container)
                return;
            const item = analysis.container.getItem(analysis.player.selectedSlotIndex);
            if (!item)
                return;
            switch (item?.typeId) {
                case 'minecraft:gold_block':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 1);
                    break;
                case 'minecraft:iron_block':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 2);
                    break;
                case 'minecraft:emerald_block':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 3);
                    break;
                case 'minecraft:diamond_block':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 4);
                    break;
                case 'minecraft:lapis_block':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 5);
                    break;
                case 'minecraft:netherite_block':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 6);
                    break;
                case 'minecraft:copper_block':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 7);
                    break;
                case 'minecraft:redstone_block':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 8);
                    break;
                default: break;
            }
            ;
            analysis.player?.playSound('fire.ignite');
        }
    };
}
;
export function WoodCamouflageTrigger() {
    return {
        onPlayerInteract(source) {
            const analysis = InteractComponentTrigger(source);
            if (analysis.item?.typeId == analysis.block.typeId)
                return;
            if (!analysis.player || !analysis.container)
                return;
            const item = analysis.container?.getItem(analysis.player.selectedSlotIndex);
            if (!item)
                return;
            switch (item?.typeId) {
                case 'minecraft:oak_planks':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 1);
                    break;
                case 'minecraft:spruce_planks':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 2);
                    break;
                case 'minecraft:birch_planks':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 3);
                    break;
                case 'minecraft:jungle_planks':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 4);
                    break;
                case 'minecraft:acacia_planks':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 5);
                    break;
                case 'minecraft:dark_oak_planks':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 6);
                    break;
                case 'minecraft:mangrove_planks':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 7);
                    break;
                case 'minecraft:cherry_planks':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 8);
                    break;
                case 'minecraft:bamboo_planks':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 9);
                    break;
                case 'minecraft:crimson_planks':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 10);
                    break;
                case 'minecraft:warped_planks':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 11);
                    break;
                default: break;
            }
            ;
            analysis.player?.playSound('fire.ignite');
        }
    };
}
;
export function StoneCamouflageTrigger() {
    return {
        onPlayerInteract(source) {
            const analysis = InteractComponentTrigger(source);
            if (analysis.item?.typeId == analysis.block.typeId)
                return;
            if (!analysis.player || !analysis.container)
                return;
            const item = analysis.container?.getItem(analysis.player.selectedSlotIndex);
            if (!item)
                return;
            switch (item?.typeId) {
                case 'minecraft:polished_basalt':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 1);
                    break;
                case 'minecraft:polished_granite':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 2);
                    break;
                case 'minecraft:polished_diorite':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 3);
                    break;
                case 'minecraft:polished_andesite':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 4);
                    break;
                case 'minecraft:polished_blackstone':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 5);
                    break;
                case 'minecraft:polished_deepslate':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 6);
                    break;
                case 'minecraft:polished_tuff':
                    native_tools.TrySetPermutation(analysis.block, 'STATE:texture', 7);
                    break;
                default: break;
            }
            ;
            analysis.player?.playSound('fire.ignite');
        }
    };
}
;
export function CrystalTankTrigger() {
    return {
        onPlayerInteract(source) {
            const analysis = InteractComponentTrigger(source);
            if (analysis.item?.typeId == analysis.block.typeId)
                return;
            const player = analysis.player;
            const container = player?.getComponent('minecraft:inventory')?.container;
            const caching = analysis.state.getState('STATE:caching');
            if (!player || !container || !analysis.item?.getTags().includes('data_tag:energy_crystal.series'))
                return;
            if (analysis.item?.getTags().includes('data_tag:eternal_crystal')) {
                const constant = server.BlockPermutation.resolve('block_energy:constant_tank');
                native_tools.TrySpawnParticle(analysis.dimension, 'constant:smoke_rune_white', analysis.block.above()?.bottomCenter());
                native_tools.TrySpawnParticle(analysis.dimension, 'constant:smoke_rune_white', analysis.block.above()?.bottomCenter());
                analysis.player?.playSound('cauldron.explode');
                analysis.block.setPermutation(constant);
                native_tools.DeleteItemStack(container, new server.ItemStack(analysis.item.typeId));
            }
            else if (caching != 8) {
                native_tools.TrySetPermutation(analysis.block, 'STATE:caching', caching + 1);
                player.playSound('block.end_portal_frame.fill');
                native_tools.DeleteItemStack(container, new server.ItemStack(analysis.item.typeId));
            }
            else if (caching == 8) {
                analysis.player?.playSound('mob.shulker.bullet.hit');
                native_tools.TrySpawnParticle(analysis.dimension, 'constant:smoke_rune_white', analysis.block.above()?.bottomCenter());
                native_tools.TrySpawnParticle(analysis.dimension, 'constant:smoke_rune_white', analysis.block.above()?.bottomCenter());
                analysis.player?.sendMessage('§c容器已满载, 无法继续填充');
                native_tools.TrySetPermutation(analysis.block, 'STATE:output', 2);
            }
        }
    };
}
;
export function MagmaPowerTrigger() {
    return {
        onPlayerInteract(source) {
            const analysis = InteractComponentTrigger(source);
            if (analysis.item?.typeId == analysis.block.typeId)
                return;
            if (!analysis.player || !analysis.container)
                return;
            const item = analysis.item;
            if (!item || item?.typeId !== 'minecraft:lava_bucket')
                return;
            const magma = analysis.state.getState('STATE:magma');
            if (magma == 15)
                return;
            native_tools.TrySetPermutation(analysis.block, 'STATE:magma', magma + 1);
            analysis.player?.playSound('bucket.fill_lava');
            analysis.container.setItem(analysis.player.selectedSlotIndex);
            native_tools.TrySpawnItem(analysis.dimension, new server.ItemStack('minecraft:bucket'), analysis.block.center());
        }
    };
}
;
export function RegionDisplayTrigger() {
    return {
        onPlayerInteract(source) {
            const analysis = InteractComponentTrigger(source);
            if (analysis.item?.typeId == analysis.block.typeId)
                return;
            effect_machine.Display(analysis.block);
        }
    };
}
;
export function RoadSignPresetsTrigger() {
    return {
        onPlayerInteract(source) {
            const analysis = InteractComponentTrigger(source);
            if (analysis.item?.typeId == analysis.block.typeId)
                return;
            effect_machine.RoadSignPresets(analysis.block);
        }
    };
}
;
export function EnchantmentDissociationTrigger() {
    return {
        onPlayerInteract(source) {
            const analysis = InteractComponentTrigger(source);
            if (analysis.item?.typeId == analysis.block.typeId)
                return;
            const player = analysis.player;
            const below = analysis.block.below();
            const container = below?.getComponent('minecraft:inventory')?.container;
            const enchantable = analysis.item?.getComponent('minecraft:enchantable');
            const enchantments = enchantable?.getEnchantments();
            function dissociation(enchantments, container, block, enchantable) {
                const number = enchantments.length;
                const blockItem = new server.ItemStack('minecraft:book', number);
                const anchor = math_tools.Vector.add(block.center(), { x: 0, y: 2, z: 0 });
                if (!native_tools.CheckItemStack(container, [blockItem]))
                    return derived_tools.ErrorMessage('<§l§b 附魔分离 §r>§4 发生错误§r', block, { text: '未能在<§l§3 方块容器 §r>内获取到足够数量的<§l§u 书本 §r>' });
                if (!realm_property.ExpendEnergy(analysis.block, -number * 1000))
                    return;
                native_tools.DeleteItemStack(container, blockItem);
                enchantments.forEach(enchantment => {
                    const item = new server.ItemStack('minecraft:enchanted_book');
                    item.getComponent('minecraft:enchantable')?.addEnchantment(enchantment);
                    native_tools.TrySpawnItem(block.dimension, item, block.center());
                });
                analysis.player?.playSound('block.enchanting_table.use');
                native_tools.TrySpawnParticle(block.dimension, 'constant:erupt_rune_purple', anchor);
                native_tools.TrySpawnParticle(block.dimension, 'constant:impact_rune_purple', anchor);
                native_tools.TrySpawnParticle(block.dimension, 'constant:excite_rune_purple', anchor);
                enchantable?.removeAllEnchantments();
            }
            if (!below || !container)
                return derived_tools.ErrorMessage('<§l§b 附魔分离 §r>§4 发生错误§r', analysis.block, { text: '未能在设备下方找到合适的<§l§3 方块容器 §r>' });
            if (!player || !enchantable || !enchantments)
                return;
            if (enchantments.length == 0)
                return;
            dissociation(enchantments, container, below, enchantable);
            analysis.container?.setItem(player.selectedSlotIndex, analysis.item);
        }
    };
}
;
export function StarEnergyInfusionTrigger() {
    return {
        onPlayerInteract(source) {
            const analysis = InteractComponentTrigger(source);
            if (analysis.item?.typeId == analysis.block.typeId)
                return;
            if (!achieve_plan.ControlEventTrigger.BlockToken('消耗星尘力补充物品数值', analysis.block, 20))
                return;
            function RestoreDurabilit() {
                const durability = analysis.item?.getComponent('minecraft:durability');
                if (!durability || durability.damage == 0 || !realm_property.ExpendEnergy(analysis.block, -durability.damage * 5))
                    return;
                durability.damage = 0;
                analysis.container?.setItem(analysis.player?.selectedSlotIndex ?? 0, analysis.item);
                ChargingSpecialEffects();
            }
            ;
            function RestoreVehiclePower() {
                const power = analysis.item?.getDynamicProperty('energy:offline_vehicle_power') ?? 3500;
                if (!realm_property.ExpendEnergy(analysis.block, 10000) || power >= 1000000)
                    return;
                analysis.item?.setDynamicProperty('energy:offline_vehicle_power', power + 10000);
                analysis.item?.setLore([`<§9§o§l 剩余能量 §r>: ${power + 10000}`]);
                analysis.container?.setItem(analysis.player?.selectedSlotIndex ?? 0, analysis.item);
                ChargingSpecialEffects();
            }
            ;
            function ChargingSpecialEffects() {
                const molang = new server.MolangVariableMap();
                const direction = math_tools.Vector.difference(analysis.block.center(), analysis.player?.location ?? { x: 0, y: 0, z: 0 });
                molang.setFloat('variable.type', 0);
                molang.setVector3('variable.direction', direction);
                native_tools.TrySpawnParticle(analysis.block.dimension, 'scripts:path_ray', analysis.block.center(), molang);
                native_tools.TrySpawnParticle(analysis.block.dimension, 'constant:erupt_rune_purple', analysis.block.center());
                native_tools.TrySpawnParticle(analysis.block.dimension, 'constant:excite_rune_purple', analysis.block.center());
                analysis.player?.playSound('block.enchanting_table.use');
            }
            ;
            if (analysis.item?.hasTag('data_tag:use_energy_to_restore_vehicle_power'))
                return RestoreVehiclePower();
            if (analysis.item?.hasTag('data_tag:use_energy_to_restore_durability'))
                return RestoreDurabilit();
        }
    };
}
;
export function FurnaceTrigger() {
    return {
        onPlayerInteract(source) {
            const analysis = InteractComponentTrigger(source);
            if (analysis.item?.typeId == analysis.block.typeId)
                return;
            if (!analysis.player || !analysis.container)
                return;
            const item = analysis.container.getItem(analysis.player.selectedSlotIndex);
            if (!item)
                return;
            if (item.typeId === 'block_unit:compressed_stone') {
                const material = analysis.state.getState('STATE:material');
                if (material != 8) {
                    native_tools.TrySetPermutation(analysis.block, 'STATE:material', material + 1);
                    native_tools.DeleteItemStack(analysis.container, new server.ItemStack(item.typeId));
                }
                else
                    analysis.player.onScreenDisplay.setTitle('§d剩余空间不足, 无法填充');
                analysis.player?.playSound('use.stone');
            }
            ;
            if (item.typeId === 'minecraft:bucket') {
                const magma = analysis.state.getState('STATE:magma');
                const anchor = math_tools.Vector.toString(analysis.block.above()?.bottomCenter(), { delimiter: ' ' });
                if (magma == 0)
                    analysis.player.onScreenDisplay.setTitle('§d储备不足, 无法提取');
                else {
                    analysis.dimension.runCommand(`loot spawn ${anchor} loot "iron_bucket/lava"`);
                    native_tools.TrySetPermutation(analysis.block, 'STATE:magma', magma - 1);
                    analysis.player?.playSound('bucket.empty_lava');
                    native_tools.DeleteItemStack(analysis.container, new server.ItemStack(item.typeId));
                }
            }
        }
    };
}
;
export function StorageTankTrigger() {
    return {
        onPlayerInteract(source) {
            const analysis = InteractComponentTrigger(source);
            if (analysis.item?.typeId == analysis.block.typeId)
                return;
            if (!analysis.player || !analysis.container)
                return;
            const item = analysis.container.getItem(analysis.player.selectedSlotIndex);
            if (!item)
                return;
            if (item.typeId === 'minecraft:bucket') {
                const magma = analysis.state.getState('STATE:magma');
                const anchor = math_tools.Vector.toString(analysis.block.above()?.bottomCenter(), { delimiter: ' ' });
                if (magma == 0)
                    analysis.player.onScreenDisplay.setTitle('§d熔岩不足, 无法提取');
                else {
                    analysis.dimension.runCommand(`loot spawn ${anchor} loot "iron_bucket/lava"`);
                    native_tools.TrySetPermutation(analysis.block, 'STATE:magma', magma - 1);
                    analysis.player?.playSound('bucket.empty_lava');
                    native_tools.DeleteItemStack(analysis.container, new server.ItemStack(item.typeId));
                }
            }
            ;
            if (item.typeId === 'minecraft:lava_bucket') {
                const magma = analysis.state.getState('STATE:magma');
                const anchor = math_tools.Vector.toString(analysis.block.above()?.bottomCenter(), { delimiter: ' ' });
                if (magma == 15)
                    analysis.player.onScreenDisplay.setTitle('§d容量不足, 无法填充');
                else {
                    analysis.dimension.runCommand(`loot spawn ${anchor} loot "iron_bucket/empty"`);
                    native_tools.TrySetPermutation(analysis.block, 'STATE:magma', magma + 1);
                    analysis.player?.playSound('bucket.fill_lava');
                    native_tools.DeleteItemStack(analysis.container, new server.ItemStack(item.typeId));
                }
            }
            ;
        }
    };
}
;
